package com.jiaorui.JMSdemo;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;


@Component
public class TopicProducer {
	
	@Autowired
	private JmsTemplate jmsTemplate;
	
	@Autowired
	private Destination topicTextDestination;
	
	
	/**
	 * �����ı���Ϣ�ķ���
	 * ʹ��jmsTemplate���з���
	 * @param text
	 */
	public void sendTextMessage(final String text){
		
		MessageCreator mc = new MessageCreator() {
			
			
			public Message createMessage(Session session) throws JMSException {
				
				return session.createTextMessage(text);
			}
		};
		
		
		jmsTemplate.send(topicTextDestination,mc);
	}
}
